﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using TowerDefense.Units;
using TowerDefense.Towers;

namespace TowerDefense
{
    public static class World
    {
        private static List<Creep> _creeps = new List<Creep>();
        private static List<Munition> _shots = new List<Munition>();

        public static List<Munition> Shots
        {
            get
            {
                return _shots;
            }
            set
            {
                _shots = value;
            }
        }
        public static List<Creep> Creeps
        {
            get
            {
                return _creeps;
            }
            set
            {
                _creeps = value;
            }
        }

        public static Queue<Map> Maps
        {
            get
            {
                return _maps;
            }
            set
            {
                _maps = value;
            }
        }
        private static Queue<Map> _maps = new Queue<Map>();

        private static Map _currentMap;

        public static Map CurrentMap
        {
            get 
            {
                if (_currentMap == null)
                    _currentMap = Maps.Dequeue();
                return World._currentMap; 
            }
            set { World._currentMap = value; }
        }


        public static Player Player
        {
            get;
            set;
        }

        public static void Update(GameTime gameTime)
        {
            _creeps.RemoveAll(c => c.CurrentState != Creep.CreepState.Moving);
            foreach (Creep creep in _creeps)
            {
                creep.Update(gameTime);
            }
            foreach (Munition sh in Shots)
            {
                sh.Update(gameTime);
            }
            Player.Update(gameTime);
        }

        public static void Draw(SpriteBatch sb)
        {
            World.CurrentMap.Draw(sb);

            foreach (Creep creep in _creeps)
            {
                creep.Draw(sb);
            }
            foreach (Munition sh in Shots)
            {
                sh.Draw(sb);
            }

            Player.Draw(sb);
        }
    }
}
